from nicegui import ui

_m_copy2clipboard_js = r"""
  let copy_text = '{content}'
  
  let temp_input = document.createElement('textarea');
  temp_input.value = copy_text;
  document.body.appendChild(temp_input);
  temp_input.select();
  document.execCommand("Copy");
  temp_input.remove();
"""


def copy2clipboard(content: str):
    ui.run_javascript(_m_copy2clipboard_js.format(content=content))


@ui.page("/")
async def main():
    ui.button("Copy to clipboard", on_click=lambda: copy2clipboard("Hello, world!"))


ui.run()
